//
//  YZWeatherView.m
//  天气预报
//
//  Created by jacoy on 16/5/3.
//  Copyright © 2016年 jacoy. All rights reserved.
// color: 224  244 249      35  188 185

#import "YZWeatherView.h"
#import "YZWeather.h"
@interface YZWeatherView ()
@property (weak, nonatomic) IBOutlet UIButton *cityButton;//城市

@property (weak, nonatomic) IBOutlet UILabel *weatherLabel;//天气

@property (weak, nonatomic) IBOutlet UILabel *tempLabel;//温度

@property (weak, nonatomic) IBOutlet UIImageView *iconView;//天气图片
@property (weak, nonatomic) IBOutlet UILabel *dateLabel;//日期

@end

@implementation YZWeatherView

+(instancetype)weatherView{
    return [[[NSBundle mainBundle]loadNibNamed:@"YZWeatherView" owner:nil options:nil]lastObject];
}


- (IBAction)switchCity:(UIButton *)sender {
    if ([self.delegate respondsToSelector:@selector(weatherViewButtonClick:)]) {
        [self.delegate weatherViewButtonClick:sender];
    }
}

-(void)setWeather:(YZWeather *)weather{
    _weather = weather;
    [self.cityButton setTitle:weather.city forState:UIControlStateNormal];

    self.tempLabel.text = weather.temperature;
    self.weatherLabel.text = weather.weather;
    self.dateLabel.text = weather.date;
    self.iconView.image = [UIImage imageNamed:@"icon_weather_default"];

    if ([weather.weather hasPrefix:@"多云"]) {
        self.iconView.image = [UIImage imageNamed:@"icon_weather_duoyun"];
    }
    if ([weather.weather hasPrefix:@"晴"]) {
        self.iconView.image = [UIImage imageNamed:@"icon_weather_qing"];
    }
    if ([weather.weather hasPrefix:@"阴"]) {
        self.iconView.image = [UIImage imageNamed:@"icon_weather_yintian"];
    }
    if ([weather.weather hasPrefix:@"雨"]||[weather.weather hasPrefix:@"小雨"]||[weather.weather hasPrefix:@"中雨"]||[weather.weather hasPrefix:@"阵雨"]||[weather.weather hasPrefix:@"雷阵雨"]||[weather.weather hasPrefix:@"大雨"]||[weather.weather hasPrefix:@"暴雨"]||[weather.weather hasPrefix:@"大暴雨"]||[weather.weather hasPrefix:@"特大暴雨"]) {
        self.iconView.image = [UIImage imageNamed:@"icon_weather_rain"];
    }
    if ([weather.weather hasPrefix:@"小雪"]||[weather.weather hasPrefix:@"中雪"]||[weather.weather hasPrefix:@"大雪"]||[weather.weather hasPrefix:@"暴雪"]) {
        self.iconView.image = [UIImage imageNamed:@"icon_weather_snow"];
    }
    
    
}

@end
